/*
 *  voice.h
 *
 *  Copyright 2007	Robert Adkins
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License, version 2.1
 *  as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this program; if not, write to
 *	Free Software Foundation, Inc.
 *	51 Franklin St., Fifth Floor
 *	Boston, MA 02110, USA.
 *
 *  This program is indebted to earlier work by Roger Butenuth and
 *  Michael Gorse who created Eflite, the speach synthesizer interface
 *  for Emacspeak.  The current program is a redesigned and rewritten
 *  implementation of Eflite's interface to CMU's Festival Lite speech
 *  synthesizer.  Note that the rewritten program is licensed under
 *  LGPL instead of the GPL to allow it to be incorporated seamlessly
 *  into LGPL libraries like vialog.
 *  
 *  This program is also indebted to T. V. Raman, the author of
 *  Emacspeak, for his profound contributions toward making software
 *  useable by the visually impaired.
 *
 */

#ifndef VOICE_H_included
#define VOICE_H_included 1

#ifdef ENABLE_NLS
#include <libintl.h>
#include <langinfo.h>
#define _(s) gettext(s)
#else
#undef _
#define _(s) s
#endif

#if defined(USE_FLITE)
#include "flite.h"
#include "flite_version.h"
#elif defined(USE_ESPEAK)
#include "speak_lib.h"
#endif

extern FILE *pipe_fp;
extern chtype attributes[];
extern int defaultno;
extern int screen_initialized;
extern int rc_dirty;
extern char *current_rcfilename;
extern char *ascii[256];
extern char *ascii2[256];

#define DEBUG 0x20000
#define NPARAMS 3
typedef struct client CLIENT;
struct client
{
  int fd;
  int change_mode[NPARAMS];
  int param[NPARAMS];
  char punct[256];
};

typedef struct setting setting;
struct setting
{
  char *name;
  char *value;
  setting *next;
};

#define LANGUAGES            2
#define LANG_BRITISH_ENGLISH 0
#define LANG_DUMMY           1

typedef struct {
    int  lang;			/* index (see defines above) */
    char *name;			/* descriptive name */
} lang_descr_t;

typedef enum {
    DONT_SPEAK = -1,
    SPEAK_VERBOSELY = 0,
    SPEAK_BRIEFLY = 1
} speak_mode;

typedef enum {
    S_SPEED,			/* 1000 = normal */
    S_PITCH,			/* 1000 = normal */
    S_VOLUME,			/* 1000 = normal */
    S_MAX
} synth_par_t;

typedef struct synth_state *synth_state_p;

typedef struct synth_struct {
    synth_state_p state;
    lang_descr_t  *lang;
    char          *name;
    void          *lib_handle;
    int (*close)(struct synth_struct *s);
    int (*synth)(struct synth_struct *s, unsigned char *buffer);
    int (*flush)(struct synth_struct *s);
    int (*clear)(struct synth_struct *s);
    int (*index_set)(struct synth_struct *s);
    int (*index_wait)(struct synth_struct *s, int id, int timeout);
    int (*get_param)(struct synth_struct *s, synth_par_t par, int *value);
    int (*set_param)(struct synth_struct *s, synth_par_t par, int value);
} synth_t;
extern synth_t *synth_open(void *context);
extern synth_t *synthptr;

typedef struct synth_state {
    int  param[S_MAX];
    int  initialized;
} synth_state_t;

typedef enum { LATER, NOW } SAY_WHEN;
typedef enum { BRIEF, FULL } SAY_MODE;
typedef enum { FILEPATH, DESCRIPTION, PASSTHRU } EXPANSION_TYPE;
typedef enum {
    NOTHING = 0x00,
    DISPLAY_BUTTON = 0x02,
    DISPLAY_LIST = 0x04,
    DISPLAY_TEXT_LINE = 0x08,
    DISPLAY_TEXT_PAGE = 0x10,
    DISPLAY_PERCENTAGE = 0x12,
    INPUT_BOX = 0x14,
    SAY_FIRST = 0x7F,
    SAY_ALL = 0xFF
} SAY_WHAT;

typedef enum {
    vTEXT_PAGE = -6
    ,vTEXT_LINE = -5
    ,vBUTTONS = -4
    ,vDIRS = -3
    ,vFILES = -2
    ,vTEXT = -1
} VSTATES;

extern int default_param[NPARAMS];
extern CLIENT speech_client;
extern setting *settings;
extern char *punct_some;
extern char *punct_all;
extern int speak_briefly;
extern SAY_WHAT say_what;

char *lookup_string(void *context, const char *name);
int lookup_int(char *name, int defval);
void es_addtext(CLIENT *client, char *buf);
void client_init(CLIENT *client);
int  s_close(synth_t *s);
int  s_synth(synth_t *s, unsigned char *buffer);
/*int  s_flush(synth_t *s);*/
int  s_clear(synth_t *s);
int  s_get_param(synth_t *s, synth_par_t par, int *value);
int  s_set_param(synth_t *s, synth_par_t par, int value);
void terror(const char *s);

void say_widget(const char *type, const char *desc, int selected);
void say_it(const char *text, ...);
char *reverse_str(char **input);
char *expand_special(char *input, char *expanded_str, EXPANSION_TYPE type);
char *expand_string(char *input, char *expanded_str, char **expansion_table);
char *expand_string_max(char *input, char *expanded_str, int max_expanded, char **expansion_table);
VSTATES set_next_vstate(VSTATES *vstate, VSTATES *prior_vstate, VSTATES next_vstate);
char *say_vstate(VSTATES vstate);
char *set_say_vstate(VSTATES vstate);

#endif /* VOICE_H_included */
